# -*- coding: utf-8 -*-
from datetime import datetime
from abc import ABC
from app.views import CommonHandler
from app.models.dao import db2meta, update,db2vectors
from app.models.model import LayerModel,MetaModel
class Layer_color_Handler(CommonHandler, ABC):
    async def put(self):
        params = self.json_params()
        meta_id,ids,color = params.values()
        for l_id in ids:
            update(LayerModel,l_id,{'customColor':color})
        # 图层颜色更新完成以后，都要将meta版本 + 1
        meta = db2meta(meta_id)
        metaid = meta['id']
        version_num = meta['mine_name'][1:]
        newVersion = 'v' + str(int(version_num) + 1)
        meta['mine_name'] = newVersion
        # # 时间也需要做更新
        meta['update_time'] = datetime.now()
        meta['create_time'] = datetime.fromisoformat(meta['create_time'])
        update(MetaModel,metaid,meta)
        # 返回更新后的 layer表格数据
        layers = db2vectors(LayerModel, meta_id)
        await self.respose(data={'status':200,'layers':layers})






